package com.ctvit.sjk.knowledge.app.pojo.dto;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ctvit.sjk.knowledge.app.pojo.domain.TabApp;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 应用查询VO
 *
 * @author heyingcheng
 * @date 2025/03/28
 */
@Getter
@Setter
@ToString
public class AppBaseDTO {

    protected String name;
    protected String desc;
    protected String prologue;
    @JsonProperty("dataset_id_list")
    protected List<String> datasetIdList;
    @JsonProperty("dialogue_number")
    protected Integer dialogueNumber;
    @JsonProperty("dataset_setting")
    protected JSONObject datasetSetting;
    @JsonProperty("model_setting")
    protected JSONObject modelSetting;
    @JsonProperty("problem_optimization")
    protected Boolean problemOptimization;
    @JsonProperty("model_id")
    protected String modelId;
    protected String icon;
    protected String type;
    @JsonProperty("work_flow")
    protected String workFlow;
    @JsonProperty("model_params_setting")
    protected JSONObject modelParamsSetting;
    @JsonProperty("stt_model_id")
    protected String sttModelId;
    @JsonProperty("stt_model_enable")
    protected Boolean sttModelEnable;
    @JsonProperty("stt_model_params_setting")
    protected JSONObject sttModelParamSetting;
    @JsonProperty("tts_model_id")
    protected String ttsModelId;
    @JsonProperty("tts_model_enable")
    protected Boolean ttsModelEnable;
    @JsonProperty("tts_type")
    protected String ttsType;
    @JsonProperty("problem_optimization_prompt")
    protected String problemOptimizationPrompt;
    @JsonProperty("tts_model_params_setting")
    protected JSONObject ttsModelParamsSetting;
    @JsonProperty("clean_time")
    protected Integer cleanTime;
    @JsonProperty("file_upload_enable")
    protected Boolean fileUploadEnable;
    @JsonProperty("file_upload_setting")
    protected JSONObject fileUploadSetting;
    @JsonProperty("tts_autoplay")
    protected Boolean ttsAutoplay;
    @JsonProperty("stt_autosend")
    protected Boolean sttAutosend;
    @JsonProperty("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected LocalDateTime createTime;
    @JsonProperty("update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected LocalDateTime updateTime;

    public TabApp assige(String userId) {
        TabApp entity = new TabApp();
        entity.setAppName(this.name);
        entity.setAppDesc(StringUtils.defaultString(this.desc));
        entity.setPrologue(StringUtils.defaultString(this.prologue));
        entity.setDialogueNum(ObjectUtils.defaultIfNull(this.dialogueNumber, NumberUtils.INTEGER_ZERO));
        entity.setDatasetSetting(JSON.toJSONString(ObjectUtils.defaultIfNull(this.datasetSetting, new JSONObject())));
        entity.setModelSetting(JSON.toJSONString(ObjectUtils.defaultIfNull(this.modelSetting, new JSONObject())));
        entity.setProblemOptimization(ObjectUtils.defaultIfNull(this.problemOptimization, Boolean.FALSE));
        entity.setProblemOptimizationPrompt(StringUtils.defaultString(this.problemOptimizationPrompt));
        entity.setModelId(StringUtils.defaultString(this.modelId));
        entity.setAppIcon(StringUtils.defaultString(this.icon));
        entity.setAppType(StringUtils.defaultString(this.type, "SIMPLE"));
        entity.setModelParamSetting(JSON.toJSONString(ObjectUtils.defaultIfNull(this.modelParamsSetting, new JSONObject())));
        entity.setWorkflow(JSON.toJSONString(ObjectUtils.defaultIfNull(this.workFlow, new JSONObject())));
        entity.setSttModelId(StringUtils.defaultString(this.sttModelId));
        entity.setSttModelEnable(ObjectUtils.defaultIfNull(this.sttModelEnable, Boolean.TRUE));
        entity.setSttModelParamSetting(JSON.toJSONString(ObjectUtils.defaultIfNull(this.sttModelParamSetting, new JSONObject())));
        entity.setSttAutosend(ObjectUtils.defaultIfNull(this.sttAutosend, Boolean.FALSE));
        entity.setTtsModelId(StringUtils.defaultString(this.ttsModelId));
        entity.setTtsModelEnable(ObjectUtils.defaultIfNull(this.ttsModelEnable, Boolean.TRUE));
        entity.setTtsModelParamSetting(JSON.toJSONString(ObjectUtils.defaultIfNull(this.ttsModelParamsSetting, new JSONObject())));
        entity.setTtsAutoplay(ObjectUtils.defaultIfNull(this.ttsAutoplay, Boolean.FALSE));
        entity.setTtsType(StringUtils.defaultString(this.ttsType));
        entity.setCleanTime(ObjectUtils.defaultIfNull(this.cleanTime, 180));
        entity.setFileUploadEnable(ObjectUtils.defaultIfNull(this.fileUploadEnable, Boolean.FALSE));
        entity.setFileUploadSetting(JSON.toJSONString(ObjectUtils.defaultIfNull(this.fileUploadSetting, new JSONObject())));
        entity.setCreateId(userId);
        entity.setCreateTime(LocalDateTime.now());
        entity.setUpdateId(userId);
        entity.setUpdateTime(LocalDateTime.now());
        return entity;
    }

}
